#include "SsongList.h"
#include <QDebug>


SsongList::SsongList(QObject* parent)
	:QObject(parent)
{


}



void SsongList::addUrl(const QUrl& url)
{
	if(!url.isEmpty())
		m_urlList.append(url);
}

void SsongList::addUrl(const QStringList& urls)
{
	for (auto str : urls)
	{
		m_urlList.append(QUrl::fromLocalFile(str));

	}

}

QUrl SsongList::getUrl(qint32 index) const
{
	return m_urlList.at(index);
}

QUrl SsongList::currentUrl() const
{
	return m_urlList.at(m_currentIndex);
}

qint32 SsongList::currentIndex() const
{
	return m_currentIndex;
}

void SsongList::setCurrentIndex(qint32 index)
{
	if (index < 0 || index >= m_urlList.size())
	{
		qWarning() << __FILE__ << __LINE__ << ":" << index << "out of index";
		return;
	}
		

	m_currentIndex = index;
}

void SsongList::prevSong()
{
	if (--m_currentIndex < 0)
	{
		m_currentIndex = m_urlList.size() - 1;
	}

}

void SsongList::nextSong()
{
	if (++m_currentIndex > m_urlList.size() - 1)
	{
		m_currentIndex = 0;
	}
}

void SsongList::firstSong()
{
	m_currentIndex = 0;
}

void SsongList::lastSong()
{
	m_currentIndex = m_urlList.size() - 1;
}